#include "date.h"
#include<qdebug.h>
date::date():hour(0),minute(0){}
date::date(QString t){
    int x=t.indexOf(":");
    hour=t.mid(0,x).toInt();
    minute=t.mid(x+1).toInt();
    //qDebug()<<hour<<minute;
}
date::date(const date & y)
{
    minute = y.minute;
    hour = y.hour;
}
date::date(int x,int y)
{
    hour = x;
    minute = y;
}
bool date::operator <(const date & y)
{
    if(hour < y.hour )return 1;
    else if(hour == y.hour)return minute < y.minute;
    else return 0;
}
bool date::operator ==(const date &y)
{
    if(hour == y.hour&& minute == y.minute)return 1;
    return 0;
}
date date::operator -(const date &y)
{
    int h = hour - y.hour;
    int m =minute - y.minute;
    if(m<0){m+=60;h--;}
    return date(h,m);
}
date date::operator +(const date & y)
{
    int h = hour + y.hour;
    int m = minute + y.minute;
    if(m>=60){m-=60;h++;}
    return date(h,m);
}
date & date::operator = (const date & y)
{
    hour = y.hour;
    minute = y.minute;
    return *this;
}
QString date::to_text(){
    QString x2;
    if (minute<10){
        x2="0"+QString::number(minute);
    }
    else{
        x2=QString::number(minute);
    }
    return QString::number(hour)+":"+x2;
}
